# coding:utf-8
import os
import configparser
import platform
#import ConfigParser


class OutlineConfig():
    def __init__(self):
        pass

    # 获取程序根目录
    def get_home_dir(self):
        home_dir = ""
        conf = configparser.ConfigParser()
        project_dir = os.path.dirname(os.path.abspath(__file__))
        conf.read(project_dir+"\\gol.cfg")
        if platform.system() == "Windows":
            home_dir = conf.get("gol", "home_dir")
        else:
            home_dir = conf.get("gol", "home_dir_linux")
        print(project_dir)
        return home_dir

    # 获取mysql连接
    def get_mysql_conn(self):
        conf = configparser.ConfigParser()
        conf.read("gol.cfg")
        host = conf.get("mysql", "host")
        port = conf.get("mysql", "port")
        dbname = conf.get("mysql", "dbname")
        user_name = conf.get("mysql", "user_name")
        password = conf.get("mysql", "password")
        return host, port, dbname, user_name, password

    # 获取mysql_dev连接
    def get_mysql_dev_conn(self):
        conf = configparser.ConfigParser()
        conf.read("gol.cfg")
        host = conf.get("dev_mysql", "host")
        port = conf.get("dev_mysql", "port")
        dbname = conf.get("dev_mysql", "dbname")
        user_name = conf.get("dev_mysql", "user_name")
        password = conf.get("dev_mysql", "password")
        return host, port, dbname, user_name, password

    # 获取mongodb的连接
    def get_mongodb_conn(self):
        conf = configparser.ConfigParser()
        conf.read("gol.cfg")
        dsn = conf.get('mongodb', 'dsn')
        return dsn

    def get_project_path(self):
        conf = configparser.ConfigParser()
        conf.read("gol.cfg")
        path = conf.get('gol', 'project_path')
        return path

    # 获取指标数据库mysql的连接
    def get_index_mysql_conn(self):
        conf = configparser.ConfigParser()
        conf.read("gol.cfg")
        host = conf.get("index_mysql", "host")
        port = conf.get("index_mysql", "port")
        dbname = conf.get("index_mysql", "dbname")
        user_name = conf.get("index_mysql", "user_name")
        password = conf.get("index_mysql", "password")
        return host, port, dbname, user_name, password

    # 获取程序根目录
    def get_home_data_dir(self):
        home_dir = ""
        conf = configparser.ConfigParser()
        conf.read("gol.cfg")
        if platform.system() == "Windows":
            home_dir = conf.get("gol", "home_data_dir")
        else:
            home_dir = conf.get("gol", "home_dir_linux")
       # print home_dir
        return home_dir


if __name__ == "__main__":
    config = OutlineConfig()
    config.get_home_dir()